<?php
/*script posting a game result to feed, takes following GET parameters:
 *ip - an IP of the device
 *result - either a (win), b (draw), c (failure)
 */
 ini_set( "display_errors", 0);
include 'configuration.php';

if(isset($_GET['ip']) && isset($_GET['result']))
{		
	//if all params set, post
	$ip1 = $_GET['ip'];
	$res = $_GET['result'];
	
	//retrieve the access token
	$link = mysql_connect('localhost', $DBUSER, $DBPASS) or die('Could not connect: ' . mysql_error());
	mysql_select_db('facebook') or die('Could not select database');
	
	if ($res=='a')
	{
		$query = "select score from users where address='$ip1'";
		$result = mysql_query($query) or die('Query failed: ' . mysql_error());
		$row = mysql_fetch_array($result, MYSQL_NUM);
		$score = $row[0];
		$score += 1;
		
		$query = "update users set score=$score where address='$ip1'";
		$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	}
	
	mysql_free_result($result);
	mysql_close($link);
	echo 'victory';
}
else
{
echo 'fail';
}

?>
